Note
Click here to download the full example code
neuPrint#
This tutorial shows how to fetch neurons from a neuPrint server.
NeuPrint is a service for presenting and analyzing connectomics data. It is used to host, for example, the Janelia EM reconstructions from a Drosophila hemibrain at https://neuprint.janelia.org/.
neuprint-python is a Python library that lets you query data directly from a neuPrint server. You can install it from PyPI:
pip3 install neuprint-python
navis.interfaces.neuprint wraps neuprint-python and adds a few new functions to fetch and convert data into NAVis objects.
# Import navis
import navis
# Import neuprint wrapper by navis
import navis.interfaces.neuprint as neu
First set up the connection: You can either pass your API token directly or store as NEUPRINT_APPLICATION_CREDENTIALS environment variable. The latter is the recommended way and we will use it here:
client = neu.Client(
"https://neuprint.janelia.org/",
# token="MYLONGTOKEN" # use this to instead pass your token directly
dataset="hemibrain:v1.2.1",
)
You can use all of neuprint's functions:
mbons, roi_info = neu.fetch_neurons(
neu.SegmentCriteria(instance=".*MBON.*", regex=True)
)
mbons.head(3)
NAVis has added three functions to neu:
navis.interfaces.neuprint.fetch_roi: returns anavis.Volumefrom a ROInavis.interfaces.neuprint.fetch_skeletons: returns fully fledgednavis.TreeNeurons- nodes, synapses, soma and allnavis.interfaces.neuprint.fetch_mesh_neuron: returnsnavis.MeshNeurons- including synapses
Let's start by fetching the mesh for the right mushroom body ROI:
mb = neu.fetch_roi("MB(R)")
mb
Out:
<navis.Volume(name=MB(R), units=1 dimensionless, color=(0.85, 0.85, 0.85, 0.2), vertices.shape=(57913, 3), faces.shape=(115856, 3))>
Next, let's fetch the skeletons of all right MBONs:
mbon_skeletons = neu.fetch_skeletons(
neu.SegmentCriteria(instance=".*MBON.*_R", regex=True), with_synapses=True
)
mbon_skeletons.head()
Out:
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 3.35it/s]
100%|##########| 1/1 [00:00<00:00, 3.35it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 3.88it/s]
100%|##########| 1/1 [00:00<00:00, 3.88it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 4.99it/s]
100%|##########| 1/1 [00:00<00:00, 4.99it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 1.34it/s]
100%|##########| 1/1 [00:00<00:00, 1.34it/s]
100%|##########| 1/1 [00:00<00:00, 3.11it/s]
100%|##########| 1/1 [00:00<00:00, 3.11it/s]
100%|##########| 1/1 [00:00<00:00, 2.63it/s]
100%|##########| 1/1 [00:00<00:00, 2.63it/s]
100%|##########| 1/1 [00:01<00:00, 1.04s/it]
100%|##########| 1/1 [00:01<00:00, 1.04s/it]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:01<00:00, 1.00s/it]
100%|##########| 1/1 [00:01<00:00, 1.00s/it]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 4.74it/s]
100%|##########| 1/1 [00:00<00:00, 4.74it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 1.55it/s]
100%|##########| 1/1 [00:00<00:00, 1.55it/s]
100%|##########| 1/1 [00:00<00:00, 3.81it/s]
100%|##########| 1/1 [00:00<00:00, 3.81it/s]
100%|##########| 1/1 [00:00<00:00, 2.55it/s]
100%|##########| 1/1 [00:00<00:00, 2.55it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 6.55it/s]
100%|##########| 1/1 [00:00<00:00, 6.54it/s]
100%|##########| 1/1 [00:00<00:00, 5.45it/s]
100%|##########| 1/1 [00:00<00:00, 5.45it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 5.14it/s]
100%|##########| 1/1 [00:00<00:00, 5.14it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:01<00:00, 1.15s/it]
100%|##########| 1/1 [00:01<00:00, 1.15s/it]
100%|##########| 1/1 [00:00<00:00, 5.39it/s]
100%|##########| 1/1 [00:00<00:00, 5.39it/s]
100%|##########| 1/1 [00:00<00:00, 1.76it/s]
100%|##########| 1/1 [00:00<00:00, 1.76it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:01<00:00, 1.22s/it]
100%|##########| 1/1 [00:01<00:00, 1.22s/it]
100%|##########| 1/1 [00:00<00:00, 4.91it/s]
100%|##########| 1/1 [00:00<00:00, 4.91it/s]
100%|##########| 1/1 [00:00<00:00, 2.97it/s]
100%|##########| 1/1 [00:00<00:00, 2.97it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:01<00:00, 1.36s/it]
100%|##########| 1/1 [00:01<00:00, 1.36s/it]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 5.29it/s]
100%|##########| 1/1 [00:00<00:00, 5.28it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 2.23it/s]
100%|##########| 1/1 [00:00<00:00, 2.23it/s]
100%|##########| 1/1 [00:00<00:00, 1.76it/s]
100%|##########| 1/1 [00:00<00:00, 1.76it/s]
100%|##########| 1/1 [00:00<00:00, 2.24it/s]
100%|##########| 1/1 [00:00<00:00, 2.24it/s]
100%|##########| 1/1 [00:00<00:00, 1.61it/s]
100%|##########| 1/1 [00:00<00:00, 1.61it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 1.81it/s]
100%|##########| 1/1 [00:00<00:00, 1.81it/s]
100%|##########| 1/1 [00:00<00:00, 2.22it/s]
100%|##########| 1/1 [00:00<00:00, 2.22it/s]
100%|##########| 1/1 [00:00<00:00, 1.30it/s]
100%|##########| 1/1 [00:00<00:00, 1.30it/s]
100%|##########| 1/1 [00:00<00:00, 1.75it/s]
100%|##########| 1/1 [00:00<00:00, 1.75it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 4.00it/s]
100%|##########| 1/1 [00:00<00:00, 4.00it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 4.24it/s]
100%|##########| 1/1 [00:00<00:00, 4.23it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 1.95it/s]
100%|##########| 1/1 [00:00<00:00, 1.95it/s]
100%|##########| 1/1 [00:01<00:00, 1.33s/it]
100%|##########| 1/1 [00:01<00:00, 1.33s/it]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 1.77it/s]
100%|##########| 1/1 [00:00<00:00, 1.77it/s]
100%|##########| 1/1 [00:01<00:00, 1.17s/it]
100%|##########| 1/1 [00:01<00:00, 1.17s/it]
100%|##########| 1/1 [00:00<00:00, 5.36it/s]
100%|##########| 1/1 [00:00<00:00, 5.36it/s]
100%|##########| 1/1 [00:00<00:00, 1.86it/s]
100%|##########| 1/1 [00:00<00:00, 1.86it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
0%| | 0/1 [00:00<?, ?it/s]
100%|##########| 1/1 [00:00<00:00, 2.32it/s]
100%|##########| 1/1 [00:00<00:00, 2.32it/s]
100%|##########| 1/1 [00:00<00:00, 2.60it/s]
100%|##########| 1/1 [00:00<00:00, 2.60it/s]
100%|##########| 1/1 [00:00<00:00, 1.67it/s]
100%|##########| 1/1 [00:00<00:00, 1.67it/s]
100%|##########| 1/1 [00:01<00:00, 1.16s/it]
100%|##########| 1/1 [00:01<00:00, 1.16s/it]
100%|##########| 1/1 [00:01<00:00, 1.41s/it]
100%|##########| 1/1 [00:01<00:00, 1.41s/it]
Co-visualize the MBONs and the MB volume:
navis.plot3d(
[mbon_skeletons[0], mb],
legend=False, # Hide the legend (more space for the plot)
)
Last (but not least), let's make a 2d plot for the tutorial's thumbnail:
import matplotlib.pyplot as plt
fig, ax = navis.plot2d(
[mbon_skeletons[0], mb],
c=(0, 0, 0, 1), # Make the neuron black
method="3d",
connectors=True,
linewidth=0.5, # Make neuron a bit thinner to emphasize the synapses
view=("x", "-z"),
)
plt.tight_layout()
All NAVis functions for analysis & visualization should work on these neurons. If not, please open an issue on Github.
Total running time of the script: ( 0 minutes 42.172 seconds)
Download Python source code: tutorial_remote_00_neuprint.py
Download Jupyter notebook: tutorial_remote_00_neuprint.ipynb
